{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "from tensorflow.examples.tutorials.mnist import input_data\n",
    "# number 1 to 10 data\n",
    "mnist = input_data.read_data_sets('MNIST_data', one_hot=True)\n",
    "\n",
    "\n",
    "def compute_accuracy(v_xs, v_ys):\n",
    "    global prediction\n",
    "    y_pre = sess.run(prediction, feed_dict={inputs: v_xs})\n",
    "    correct_prediction = tf.equal(tf.argmax(y_pre,1), tf.argmax(v_ys,1))\n",
    "    accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))\n",
    "    result = sess.run(accuracy, feed_dict={inputs: v_xs, outputs: v_ys})\n",
    "    return result\n",
    "\n",
    "#定义相关参数\n",
    "in_size = 784        # 输入的尺寸\n",
    "out_size = 10        # 输出的尺寸\n",
    "learning_rate = 0.1  #学习率\n",
    "max_epochs = 3000    # 最大训练步数\n",
    "\n",
    "inputs = tf.placeholder(tf.float32, [None, in_size]) # 28x28\n",
    "outputs = tf.placeholder(tf.float32, [None, out_size])# 10\n",
    "\n",
    "                         \n",
    "Weights = tf.Variable(tf.random_normal([in_size, out_size]))\n",
    "biases = tf.Variable(tf.zeros([1, out_size]) + 0.1,)\n",
    "\n",
    "prediction = tf.nn.softmax(tf.matmul(inputs, Weights) + biases)\n",
    "#################################################################\n",
    "# 请在下面补全交叉熵 和 训练两个节点。\n",
    "cross_entropy = \n",
    "\n",
    "train_step = \n",
    "\n",
    "#################################################################\n",
    "sess = tf.Session()\n",
    "init = tf.global_variables_initializer() # 注意tensorflow 版本在 0.12 以后，才能执行这句命令\n",
    "sess.run(init)\n",
    "for i in range(max_epochs):\n",
    "    batch_xs, batch_ys = mnist.train.next_batch(100)\n",
    "    sess.run(train_step, feed_dict={inputs: batch_xs, outputs: batch_ys})\n",
    "    if i % 500 == 0:\n",
    "        print(compute_accuracy(\n",
    "            mnist.test.images, mnist.test.labels))"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [conda root]",
   "language": "python",
   "name": "conda-root-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
